// pages/case/case.js
const app = getApp();
import { _get_project_case_list, _get_project_case_dcit } from '../../utils/qiaofinn'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    houses: [],
    next_page: null,
    TabCur: 0,
    scrollLeft: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    _get_project_case_list({}, res => {
      if (res.status) {
        this.setData({
          houses: res.data.dataList,
          next_page: res.data.next
        })
      }
    })
    _get_project_case_dcit(res => {
      if (res.status) {
        this.setData({
          project_case_styles: res.data.style
        })
      }
    })
  },
  tabSelect(e) {
    const style = e.currentTarget.dataset.style
    this.setData({
      style: style,
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
    _get_project_case_list({ style: style }, res => {
      if (res.status) {
        this.setData({
          houses: res.data.dataList,
          next_page: res.data.next
        })
      }
    })
  },
  /**
 * 页面上拉触底事件的处理函数
 */
  onReachBottom: function () {
    const { next_page, houses } = this.data
    if (next_page) {
      _get_project_case_list({ currentPage: next_page, style: this.data.style }, res => {
        this.setData({
          houses: houses.concat(res.data.dataList),
          next_page: res.data.next
        })
      })
    } else {
      wx.showToast({
        title: '没有更多的数据',
        icon: 'none',
      })
    }
  },

  toCaseDetailTap(res) {
    wx.navigateTo({
      url: './detail/detail?houseId=' + res.currentTarget.dataset.id
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})